﻿using SUNRPA.CONTROLS.IMPL.domain;
using SUNRPA.CONTROLS.IMPL.domain.constant;
using SUNRPA.CONTROLS.IMPL.domain.flowItemParam;
using SUNRPA.CONTROLS.IMPL.domain.flowRunningVar;
using SUNRPA.CONTROLS.IMPL.util;
using System.Collections.Concurrent;

namespace SUNRPA.CONTROLS.IMPL.controls {
    public class CreateDirNAction:BaseControlActions {
        public override int Execute(int currentIndex, FlowItem item, ConcurrentDictionary<string, ConcurrentDictionary<string, RPAVariableDefineWrapper>> globleData, List<FlowItem> flowItems) {
            CreateDirNParam? param = item.ControlParam as CreateDirNParam;
            string fatherDir = param.FatherDir;
            string dirName = param.DirName;
            string outVarName = param.OutVarName;
            this.GetStringVar(ref fatherDir, globleData);
            this.GetStringVar(ref dirName, globleData);
            string dirPath = fatherDir + Path.DirectorySeparatorChar + dirName;
            DirectoryInfo di = Directory.CreateDirectory(dirPath);
            this.saveVar(globleData, outVarName, new StringModel(outVarName, di.FullName), DefaultContents.RUNNING_PARAM);
            return currentIndex;
        }
    }
}
